#include <stdio.h>
#include <stdlib.h>
typedef struct nold
{
    int data;
    struct nold *lchild,*rchild;
}Bitnold,*Bitree;
void creat(int prer[],int i,int j,int mid[],int k,int h,Bitnold **t)
{
    *t=(Bitnold*)malloc(sizeof(Bitnold));
    (*t)->data=prer[i];
    int m=k;
    while(prer[i]!=mid[m])
        m++;
    if(m==k)
        (*t)->lchild=NULL;
    else
       creat(prer,i+1,i+m-k,mid,k,m-1,&(*t)->lchild);
    if(m==h)
        (*t)->rchild=NULL;
    else
        creat(prer,i+m-k+1,j,mid,m+1,h,&(*t)->rchild);
}
 
int main()
{
    int i;
    Bitnold *root;
    int n;
    scanf("%d",&n);
    int mid[n];
    int prer[n];
    for(i=0;i<n;i++)
     scanf("%d",&mid[i]);
     for(i=0;i<n;i++)
        scanf("%d",&prer[i]);
     creat(prer,0,n-1,mid,0,n-1,&root);
    
  Bitree queue[n];
  int rear=0;
  int j=0;
  int front=-1;
  int arr[n];
  if(root!=NULL)
    queue[rear]=root;
  while(front!=rear)
  {
      front++;
      arr[j]=queue[front]->data;
      j++;
      if(queue[front]->rchild!=NULL)
      {
          rear++;
          queue[rear]=queue[front]->rchild;
      }
      if(queue[front]->lchild!=NULL)
      {
          rear++;
          queue[rear]=queue[front]->lchild;
      }
  }
 // printf("shgkljfdjllh");
  printf("%d",arr[0]);
  for(i=1;i<j;i++)
    printf(" %d",arr[i]);
    return 0;
}